<?php
    Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/bootstrap-datepicker.js', CClientScript::POS_BEGIN);
    Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/locale/bootstrap-datepicker.zh-CN.js', CClientScript::POS_BEGIN);
    Yii::app()->clientScript->registerScriptFile(Yii::app()->baseUrl . '/js/thickbox.js', CClientScript::POS_BEGIN);
    Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/css/thickbox.css', CClientScript::POS_END);
    Yii::app()->clientScript->registerCssFile(Yii::app()->baseUrl . '/css/datepicker.css', CClientScript::POS_END);
    Yii::app()->clientScript->registerScript('datepicker', "$('.datepicker').datepicker({autoclose:true,
        clearBtn:true,
        todayBtn:true,
        todayHighlight:true,
        format: 'yyyy-mm-dd',
        language:'zh-CN'});", CClientScript::POS_END);

    $state = array(
        'Kuala Lumpur' => 'Kuala Lumpur',
        'Penang' => 'Penang',
        'Perlis' => 'Perlis',
        'Perak' => 'Perak',
        'Selangor' => 'Selangor',
        'Labuan' => 'Labuan',
        'Putrajaya' => 'Putrajaya',
        'Johor' => 'Johor',
        'Kedah' => 'Kedah',
        'Kelantan' => 'Kelantan',
        'Malacca' => 'Malacca',
        'Negeri Sembilan' => 'Negeri Sembilan',
        'Pahang' => 'Pahang',
        'Sabah' => 'Sabah',
        'Sarawak' => 'Sarawak',
        'Terengganu' => 'Terengganu'
    );
    $country = array('Malaysia' => 'Malaysia');
    $race = array('Chinese' => 'Chinese', 'Malay' => 'Malay', 'Indian' => 'Indian');
    $religion = array('Buddhist' => 'Buddhist', 'Islamic' => 'Islamic', 'Hindu' => 'Hindu');

    $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
        'id' => 'customers-form',
        'enableAjaxValidation' => true,
//        'htmlOptions' => array(
//            'enctype' => 'multipart/form-data',
//        ),
    ));
?>

<p class="help-block">Fields with <span class="required">*</span> are required.</p>

<?php echo $form->errorSummary($model); ?>
<?php
    $current_user = User::model()->findByPk(Yii::app()->user->id);
    $user_code = $current_user->user_code;
    $last_customer_no = $current_user->last_customer_no;

    echo $form->textFieldRow($model, 'customer_code', array('class' => 'span2',
        'maxlength' => 20,
        'readonly' => 'readonly',
        'value' => (isset($_GET['id'])) ? $model->customer_code : sprintf('%s%06d', $user_code, $last_customer_no + 1)));
    echo $form->hiddenRow($model, 'user_id', array('value' => Yii::app()->user->id));
    echo $form->hiddenRow($model, 'updateby_user_id', array('value' => Yii::app()->user->id));
?>
<div class="tabbable"> <!-- Only required for left/right tabs -->
    <ul class="nav nav-tabs">
        <li class="active"><a href="#tab1" data-toggle="tab"><?php echo t('Basic Info'); ?></a></li>
        <li><a href="#tab2" data-toggle="tab"><?php echo t('Second Contact'); ?></a></li>
        <li><a href="#tab3" data-toggle="tab"><?php echo t('Guarantee Contact'); ?></a></li>
        <li><a href="#tab4" data-toggle="tab"><?php echo t('Photos'); ?></a></li>
    </ul>
    <div class="tab-content">
        <div class="tab-pane active" id="tab1">
            <?php echo $form->textFieldRow($model, 'firstname', array('class' => 'span3', 'maxlength' => 50)); ?>
            <?php echo $form->textFieldRow($model, 'lastname', array('class' => 'span3', 'maxlength' => 50)); ?>
            <?php echo $form->textFieldRow($model, 'birthday', array('class' => 'span3 datepicker')); ?>
            <?php echo $form->dropDownListRow($model, 'race', $race, array('class' => 'span3', 'maxlength' => 50)); ?>
            <?php echo $form->dropDownListRow($model, 'religion', $religion, array('class' => 'span3', 'maxlength' => 50)); ?>
            <?php echo $form->textFieldRow($model, 'newic', array('class' => 'span3', 'maxlength' => 16)); ?>
            <?php echo $form->textFieldRow($model, 'address1', array('class' => 'span3', 'maxlength' => 100)); ?>
            <?php echo $form->textFieldRow($model, 'address2', array('class' => 'span3', 'maxlength' => 100)); ?>
            <?php echo $form->textFieldRow($model, 'postcode', array('class' => 'span1', 'maxlength' => 5)); ?>
            <?php echo $form->textFieldRow($model, 'city', array('class' => 'span3', 'maxlength' => 50)); ?>
            <?php
                echo $form->dropDownListRow($model, 'state', $state, array('class' => 'span3', 'maxlength' => 50));
            ?>
            <?php echo $form->dropDownListRow($model, 'country', $country, array('class' => 'span3', 'maxlength' => 50)); ?>
        </div>
        <div class="tab-pane" id="tab2">
            <?php echo $form->textFieldRow($model, 'sec_address1', array('class' => 'span3', 'maxlength' => 100)); ?>
            <?php echo $form->textFieldRow($model, 'sec_address2', array('class' => 'span3', 'maxlength' => 100)); ?>
            <?php echo $form->textFieldRow($model, 'sec_postcode', array('class' => 'span1', 'maxlength' => 5)); ?>
            <?php echo $form->textFieldRow($model, 'sec_city', array('class' => 'span3', 'maxlength' => 50)); ?>
            <?php echo $form->dropDownListRow($model, 'sec_state', $state, array('class' => 'span3', 'maxlength' => 50)); ?>
            <?php echo $form->dropDownListRow($model, 'sec_country', $country, array('class' => 'span3', 'maxlength' => 50)); ?>
        </div>
        <div class="tab-pane" id="tab3">
            <?php echo $form->textFieldRow($model, 'guarantee_firstname', array('class' => 'span3', 'maxlength' => 50)); ?>
            <?php echo $form->textFieldRow($model, 'guarantee_lastname', array('class' => 'span3', 'maxlength' => 50)); ?>
            <?php
                echo $form->textFieldRow($model, 'guarantee_birthday', array('class' => 'span3 datepicker'));
            ?>

            <?php echo $form->textFieldRow($model, 'guarantee_newic', array('class' => 'span3', 'maxlength' => 16)); ?>
            <?php echo $form->textFieldRow($model, 'guarantee_address1', array('class' => 'span3', 'maxlength' => 100)); ?>
            <?php echo $form->textFieldRow($model, 'guarantee_address2', array('class' => 'span3', 'maxlength' => 100)); ?>
            <?php echo $form->textFieldRow($model, 'guarantee_postcode', array('class' => 'span1', 'maxlength' => 5)); ?>
            <?php echo $form->textFieldRow($model, 'guarantee_city', array('class' => 'span3', 'maxlength' => 50)); ?>
            <?php echo $form->dropDownListRow($model, 'guarantee_state', $state, array('class' => 'span3', 'maxlength' => 50)); ?>
            <?php echo $form->dropDownListRow($model, 'guarantee_country', $country, array('class' => 'span3', 'maxlength' => 50)); ?>
        </div>
        <div class="tab-pane" id="tab4">
            <?php
                if ($model->galleryBehavior->getGallery() === null) {
                    echo '<p>' . t('Before add photos to the customer, you need to save customer first.') . '</p>';
                } else {
                    $this->widget('ext.galleryManager.GalleryManager', array(
                        'gallery' => $model->galleryBehavior->getGallery(),
                        'controllerRoute' => 'gallery', //route to gallery controller
                    ));
                }
            ?>
        </div>
    </div>
</div>

<?php //echo $form->textFieldRow($model, 'createdate', array('class' => 'span3'));    ?>
<?php //echo $form->textFieldRow($model, 'modifydate', array('class' => 'span3'));   ?>

<div class="form-actions">
    <?php
        $this->widget('bootstrap.widgets.TbButton', array(
            'buttonType' => 'submit',
            'type' => 'primary',
            'label' => t($model->isNewRecord ? 'Create' : 'Save'),
            'htmlOptions' => array('class' => 'span1'),
            'icon' => 'icon-ok icon-white',
        ));
        $this->widget('bootstrap.widgets.TbButton', array(
            'buttonType' => 'Button',
            'type' => 'primary',
            'label' => t('Cancel'),
            'url' => Yii::app()->createUrl('customers/index'),
            'htmlOptions' => array('class' => 'span1'),
            'icon' => 'icon-remove icon-white',
        ));
    ?>
</div>

<?php $this->endWidget(); ?>
